package com.ujn.zhxy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ujn.zhxy.mapper.AdminMapper;
import com.ujn.zhxy.mapper.GradeMapper;
import com.ujn.zhxy.pojo.Admin;
import com.ujn.zhxy.pojo.Grade;
import com.ujn.zhxy.service.AdminService;
import com.ujn.zhxy.service.GradeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service("gradeServiceImpl") //括号内为id
@Transactional //事务控制
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade> implements GradeService {
    @Override
    public IPage<Grade> getGradeByOpr(Page<Grade> pageParam, String gradeName) {

        QueryWrapper<Grade> queryWrapper = new QueryWrapper();
        if (!StringUtils.isEmpty(gradeName)) {
            queryWrapper.like("name",gradeName);
        }

        queryWrapper.orderByDesc("id");

        Page<Grade> page = baseMapper.selectPage(pageParam, queryWrapper);
        return page;

    }

    @Override
    public List<Grade> getGrades() {
        QueryWrapper<Grade> queryWrapper = new QueryWrapper();
        queryWrapper.select("name");
        List<Grade> grades = baseMapper.selectList(queryWrapper);
        return grades;
    }


    //ServiceImpl<M,T>包含了针对于IService的实现
}
